package bryant.common.core.service.impl;

import bryant.common.core.entity.SysRole;
import bryant.common.core.entity.SysUser;
import bryant.common.core.mapper.SysUserMapper;
import bryant.common.core.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 系统用户Service
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

	@Autowired
	SysUserMapper userMapper;

	/**
	 * 根据用户名称查询用户信息
	 * 
	 * @param username 用户名称
	 * @return
	 */
	@Override
	public SysUser findUserByUserName(String username) {
		return this.baseMapper.selectOne(
				new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserName, username).ne(SysUser::getStatus, "1"));
	}

	/**
	 * 根据用户ID查询角色
	 * 
	 * @param userId 用户ID
	 * @return
	 */
	@Override
	public List<SysRole> findRoleByUserId(String userId) {
		return this.userMapper.findRoleByUserId(userId);
	}

}
